﻿using System;
using System.Windows.Forms;
using System.Threading;

namespace SpriteTool
{
    public partial class ProgressForm : Form
    {
        EventHandler eHandler;

        public ProgressForm(EventHandler eHandler)
        {
            InitializeComponent();
            // disable the ok button first
            btnOk.Enabled = false;

            this.eHandler = eHandler;
        }

        /// <summary>
        /// Sets the label above the progress bar
        /// </summary>
        public void SetStatus(string status)
        {
            lblStatus.Text = status;
            Application.DoEvents();
        }

        /// <summary>
        /// Sets the value of the progress bar
        /// </summary>
        public void SetProgress(int progress)
        {
            pbProgress.Value = progress;
            Application.DoEvents();
        }

        /// <summary>
        /// Enables the form to be closed
        /// </summary>
        public void Completed()
        {
            pbProgress.Value = 100;
            btnOk.Enabled = true;
        }

        /// <summary>
        /// Closes the form
        /// </summary>
        private void btnOk_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// Executes the event after the form is shown
        /// </summary>
        private void ProgressForm_Shown(object sender, EventArgs e)
        {
            eHandler(this, null);
        }
    }
}
